﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Security.Principal;
using System.Text;

namespace Cosoware.Web.Documents
{
    /// <summary>
    /// Represents a general document.
    /// </summary>
    [Table(Name = "tb_Cosoware_Documents")]
    public class Document
    {
        protected Guid _id;

        protected string _title;

        protected string _annotation;

        protected string _content;

        protected string _url;

        protected bool _isPublished;

        protected DateTime _published;

        /// <summary>
        /// Gets the document identifier.
        /// </summary>
        /// <value>The document identifier.</value>
        [Column(IsPrimaryKey = true, Storage = "_id")]
        public Guid ID
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// Gets or sets the document title.
        /// </summary>
        /// <value>The document title.</value>
        [Column(Storage = "_title")]
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        [Column(Storage = "_annotation")]
        public string Annotation
        {
            get { return _annotation ; }
            set { _annotation = value; }
        }

        /// <summary>
        /// Gets or sets the document content.
        /// </summary>
        /// <value>The document content.</value>
        [Column(Storage = "_content")]
        public string Content
        {
            get { return _content; }
            set { _content = value;  }
        }

        /// <summary>
        /// Gets or sets the author of document.
        /// </summary>
        /// <value>The author.</value>
        public IIdentity Author { get; set; }

        /// <summary>
        /// Gets or sets the permanent document URL.
        /// </summary>
        /// <value>The permanent document URL.</value>
        [Column(Storage = "_url", Name = "PermanentLink")]
        public string Url
        {
            get { return _url; }
            set { _url = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether current document is published.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if current document is published; otherwise, <c>false</c>.
        /// </value>
        [Column(Storage = "_isPublished", Name = "IsPublished")]
        public bool IsPublished
        {
            get { return _isPublished; }
            set { _isPublished = value; }
        }

        /// <summary>
        /// Gets or sets the publication date.
        /// </summary>
        /// <value>The publication date.</value>
        [Column(Storage = "_published", Name = "PublicationDate")]
        public DateTime Published
        {
            get { return _published; }
            set { _published = value; }
        }

        /// <summary>
        /// Gets or sets the creation date.
        /// </summary>
        /// <value>The created.</value>
        public DateTime Created { get; internal set; }

        /// <summary>
        /// Gets or sets the modification date.
        /// </summary>
        /// <value>The modified.</value>
        public DateTime Modified { get; internal set; }

        /// <summary>
        /// Changes document state from selected document.
        /// </summary>
        /// <param name="document">The document.</param>
        internal void ApplyChanges(Document document)
        {
            this.ID = document.ID;
            this.Title = document.Title;
            this.Annotation = document.Annotation;
            this.Content = document.Content;
        }
    }
}
